﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using Microsoft.Xna.Framework;
using Tomahawk.Runtime.Logic.UI;
using Tomahawk.Runtime.Canvas.Sprite;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace Tomahawk.Runtime.Timeline
{
    public class DesaturateEffectTrack : SpriteEffectTrack
    {
        [XmlElement("Saturation")]
        public string saturation = "";

        private float value = 1.0f;
        private Curve curveSaturation = new Curve();

        public DesaturateEffectTrack() : base() { }

        public DesaturateEffectTrack(string name) : base(name) { }

        protected override string GetEffectFile()
        {
            return @"Tomahawk.Content\SpriteEffects\DesaturateEffect";
        }

        protected override void OnLoadEffectParameters(Effect effect)
        {
            effect.Parameters["Saturation"].SetValue(value);
        }

        protected override bool OnLoad(GraphicsDevice graphics, ContentManager contentManager)
        {
            curveSaturation = LoadCurve(contentManager, saturation);

            return base.OnLoad(graphics, contentManager);
        }

        public override void SortKeys() { }

        public override bool Update(float time)
        {
            if (curveSaturation == null)
            {
                return false;
            }

            value = curveSaturation.Evaluate(time);

            return true;
        }
    }
}
